//
//  HLMainTabBar.swift
//  weibo-snh
//
//  Created by 黄力 on 15/12/14.
//  Copyright © 2015年 HLTest. All rights reserved.
//

import UIKit

class HLMainTabBar: UITabBar {
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        //添加
        addSubview(shareBtn)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置子控件frame
    override func layoutSubviews() {
        super.layoutSubviews()
        //定义每个按钮的尺寸
        let btnW = bounds.width / 5
        let btnH = bounds.height
        //定义一个索引
        var index: CGFloat = 0
        //遍历子控件
        for subview in subviews {
//            print(subview.classForCoder)
            //当是系统自带的按钮时
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                //计算x
                let btnX = btnW * index
                //设置frame
                subview.frame = CGRectMake(btnX, 0, btnW, btnH)
                //修改索引
                index += (index == 1 ? 2:1)
            }
            //当时自己添加的按钮时
            if subview.isKindOfClass(UIButton) {
                subview.frame = CGRectMake(btnW * 2, 0, btnW, btnH)
            }
        }
    }
    
    private lazy var shareBtn: UIButton = UIButton(imageName: "tabbar_compose_icon_add", backImageName: "tabbar_compose_button")

}
